import 'package:flutter/material.dart';

class Product {
  final String name;//商品名称
  final String description;//商品描述
  Product(this.name,this.description);
}

void main(){
  runApp(MyApp());
}

class MyApp extends StatelessWidget{
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return MaterialApp(
      title: 'flutter 导航',
      theme: ThemeData(
        //主题色 蓝色
        primarySwatch: Colors.blue,
      ),
      home: ProductList(
        products:List.generate(30, (i) => Product('商品 $i', '这是商品详情，编号 $i'))
      ),
    );
  }
}

class ProductList extends StatelessWidget{
  final List<Product> products;
  ProductList({Key key,@required this.products}):super(key:key);
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('商品列表'),
      ),
      body:ListView.builder(
          itemCount: products.length,
          itemBuilder: (context,index){
             return ListTile(
               title: Text(products[index].name),
               onTap: (){
                 Navigator.push(
                     context,
                     MaterialPageRoute(
                        builder: (context) => ProductDetail(product:products[index])
                     )
                 );
               },
             );
          }),
    );
  }
}


class ProductDetail extends StatelessWidget{
  final Product product;
  ProductDetail({Key key,@required this.product}):super(key:key);
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('${product.name}'),
      ),
      body: Center(
        child: Text('${product.description}'),
      ),
    );
  }
}